/**
* 基础菜单 商品管理
*/
<template>
  <div>

    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>新闻管理</el-breadcrumb-item>
    </el-breadcrumb>

    <news-item-list v-on:onRowEditClick="onRowEditClick"
                        @setMainLoadingFalse="isMainListLoading=false"

                      :categoryList.sync="categoryList"
                        :isMainListLoading.sync="isMainListLoading"></news-item-list>



  <news-item-edit :dialogVisible.sync="editFormVisible"
                      :rowData.sync="editForm"
                      :categoryList.sync="categoryList"
                      @onDialogClose="onEditDialogClosed"
  ></news-item-edit>


  </div>
</template>

<script>
    import newsItemEdit from "./newsItemEdit";
    import newsItemList from "./newsItemList"
    import axios from "axios"
    import {cmsApi} from '../../api/baseApi';

    export default {
        components: {
            newsItemEdit,
            newsItemList
        },
        data() {
            return {
                isMainListLoading: false, //是显示加载
                editFormVisible: false, //控制编辑页面显示与隐藏
                title: '添加',
                editForm: Object,
                categoryList:[]
            }
        },
        mounted(){
          this.getCategoryList();
        },
        methods: {
            //显示编辑界面
            onRowEditClick: function(row) {
                if (row!=null && row != undefined) {
                    this.editForm = row;
                } else {
                    this.editForm = {};
                }
                this.editFormVisible = true;
            },
            onEditDialogClosed:function(saveOrNot){
              this.editFormVisible = false;
              if(saveOrNot){
                  this.isMainListLoading = true;
              }
            },
            //获取栏目列表
            getCategoryList(){
                axios.post(cmsApi+"news-item-category/list",{})
                    .then(res => {
                        this.loading = false
                        if (res.data.code !=1) {
                            this.$message({
                                type: 'info',
                                message: res.message
                            })
                        } else {
                            this.categoryList = res.data.data.records;
                        }
                    })
                    .catch(err => {
                        this.$message.error('新闻栏目加载失败！')
                    })
            }
        }
    }
</script>

